package com.font.web.zhongyao;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.ApiController;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.font.bean.YangSheng;
import com.font.bean.result.Result;
import com.font.service.YangShengService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;

/**
 * (YangSheng)表控制层
 *
 * @author makejava
 * @since 2023-07-19 13:52:14
 */
@RestController
@RequestMapping("yangSheng")
public class YangShengController extends ApiController {
    /**
     * 服务对象
     */
    @Resource
    private YangShengService yangShengService;

    @RequestMapping("list")
    public Result prescriptionList(
            @RequestParam(value = "yangKey",required = false) String yangKey,
            @RequestParam(value = "currentPage",required = false,defaultValue = "1") Integer currentPage,
            @RequestParam(value = "pageSize",required = false,defaultValue = "5") Integer pageSize

    ){
        LambdaQueryWrapper<YangSheng> yangShengLambdaQueryWrapper = new LambdaQueryWrapper<YangSheng>()
                .eq(StrUtil.isNotBlank(yangKey),YangSheng::getYangKey, yangKey);


        IPage<YangSheng> page = yangShengService.page(new Page<YangSheng>(currentPage,pageSize),yangShengLambdaQueryWrapper);
        int pages = page.getRecords().size();
        long pages2 = page.getTotal();
        HashMap<String, Object> map = new HashMap<>();
        map.put("page",page);
        map.put("pages",pages);
        return Result.success(map);
    }

    @RequestMapping("timelist")
    public Result timelist(){
        QueryWrapper<YangSheng> queryWrapper = new QueryWrapper<YangSheng>().orderByDesc("yang_time").last("LIMIT 5");
        List<YangSheng> list = yangShengService.list(queryWrapper);

        return Result.success(list);
    }
}

